-- UIGDActivityOption
-- Created by chengb May/7/2016
-- GD活动选项

require "game/ui/form/gd/activity/UIGDOpenActivity"
require "game/ui/form/gd/activity/UIGDCloseActivity"

UIGDActivityOption = class("UIGDActivityOption", function()
    return cc.Layer:create();
end);

function UIGDActivityOption.create()
    return UIGDActivityOption.new();
end

-- 构造函数
function UIGDActivityOption:ctor()
    self:setName("UIGDActivityOption");
    local node = cc.CSLoader:createNode("layout/GD/OptionSelect.csb");
    self:addChild(node);
    self.node = node;
    local btnOption1 = findChildByName(self.node, "CT/option1");
    local btnOption2 = findChildByName(self.node, "CT/option2");
    local btnBack    = findChildByName(self.node, "BT/btn_back");
    self.btnOption1 = btnOption1;
    self.btnOption2 = btnOption2;

    self:setLocalZOrder(UIMgr.BONUS_NOTIFY_ZORDER + 100000);

    -- 注册点击事件
    self:registerTouchEvent();

    -- 重绘
    self:redraw();

    -- 适配
    self:resize();

    self:registerScriptHandler(function(ev)
        if ev == "exit" then
            cclog("UIGDActivityOption 界面析构清理");
        end
    end);
end

-- 注册点击事件
function UIGDActivityOption:registerTouchEvent()
    -- 开启活动
    local function onOption1Click(sender, eventType)
        if eventType == ccui.TouchEventType.ended then
            UIMgr.getCurrentScene():removeFormByName("UIGDOpenActivity");
            local uiForm = UIGDOpenActivity.create();
            UIMgr.getCurrentScene():addForm(uiForm);
        end
    end
    self.btnOption1:addTouchEventListener(onOption1Click);
    TextStyleM.setTextStyle(self.btnOption1, TextStyleM.TEXT_SIZE_MIDDLE, TextStyleM.TEXT_COLOR_BROWN_YELLOW, true);
    self.btnOption1:setTitleText(getLocStr("open_activity"));

    -- 关闭活动
    local function onOption2Click(sender, eventType)
        if eventType == ccui.TouchEventType.ended then
            UIMgr.getCurrentScene():removeFormByName("UIGDCloseActivity");
            local uiForm = UIGDCloseActivity.create();
            UIMgr.getCurrentScene():addForm(uiForm);
        end
    end
    self.btnOption2:addTouchEventListener(onOption2Click);
    TextStyleM.setTextStyle(self.btnOption2, TextStyleM.TEXT_SIZE_MIDDLE, TextStyleM.TEXT_COLOR_BROWN_YELLOW, true);
    self.btnOption2:setTitleText(getLocStr("close_activity"));

    -- 返回
    local btnBack    = findChildByName(self.node, "BT/btn_back");
    local function onBackClick(sender, eventType)
        if eventType == ccui.TouchEventType.ended then
            -- 关闭当前界面
            UIMgr.getCurrentScene():removeFormByName("UIGDActivityOption");
        end
    end
    AddBackEventHandler(self, btnBack, onBackClick);
    TextStyleM.setTextStyle(btnBack, TextStyleM.TEXT_SIZE_MIDDLE, TextStyleM.TEXT_COLOR_BROWN_YELLOW, true);
    btnBack:setTitleText(getLocStr("btn_text_back"));
end

-- 重绘
function UIGDActivityOption:redraw()

end

-- 适配
function UIGDActivityOption:resize()
    local node = self.node
    AlignM.fitToScreen(node, "bg");

    -- CT居中并缩放至合适大小
    AlignM.alignToCenter(node, "CT");

    -- BT底部居中并缩放至合适大小
    AlignM.alignToBottomCenter(node, "BT");
end









